package com.yunfeisoft.business.dao.impl.postgres;

import com.applet.base.ServiceDaoImpl;
import com.applet.sql.builder.WhereBuilder;
import com.applet.utils.Page;
import com.yunfeisoft.business.dao.inter.CmsSubjectProductRelationDao;
import com.yunfeisoft.business.model.CmsSubjectProductRelation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * ClassName: CmsSubjectProductRelationDaoImpl
 * Description: 专题商品关系表Dao实现
 * Author: Jackie liu
 * Date: 2020-06-02
 */
@Repository
public class CmsSubjectProductRelationDaoImpl extends ServiceDaoImpl<CmsSubjectProductRelation, String> implements CmsSubjectProductRelationDao {

    @Override
    public Page<CmsSubjectProductRelation> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            initPageParam(wb, params);
        }
        return queryPage(wb);
    }

    @Override
    public List<CmsSubjectProductRelation> queryBySubjectId(String subjectId) {
        if (StringUtils.isBlank(subjectId)) {
            return new ArrayList<>();
        }

        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("subjectId", subjectId);
        return query(wb);
    }

    @Override
    public int removeBySubjectId(String subjectId) {
        if (StringUtils.isBlank(subjectId)) {
            return 0;
        }

        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("subjectId", subjectId);
        return deleteByCondition(wb);
    }
}